package com.brush.web.controller.syspost;

import com.brush.common.core.controller.BaseController;
import com.brush.common.core.domain.R;
import com.brush.system.domain.req.syspost.SysPostAddReq;
import com.brush.system.domain.req.syspost.SysPostEditReq;
import com.brush.system.domain.req.syspost.SysPostQueryReq;
import com.brush.system.domain.resp.syspostresp.SysPostResp;
import com.brush.system.service.SysPostService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * ClassName: SysPostController
 * Package: com.brush.web.controller.syspost
 * Description:
 *
 * @Author luo
 * @Create 2024/8/25 15:32
 * @Version 1.0
 */
@Api(tags = "后台-岗位管理api")
@RestController
@RequestMapping(value = "/admin/post")
public class SysPostController extends BaseController {

    @Autowired
    private SysPostService sysPostService;

    @PreAuthorize("@ss.hasPermi('system:post:list')")
    @ApiOperation(value = "分页查询")
    @GetMapping(value = "/list")
    public R<PageInfo<SysPostResp>> list(SysPostQueryReq req) {
        PageInfo<SysPostResp> page = this.sysPostService.paginationQuery(req);
        return R.ok(page);
    }

    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('system:post:add')")
    @PostMapping
    public R add(@RequestBody @Valid SysPostAddReq req) {
        boolean result = this.sysPostService.add(req);
        return super.isSuccess(result);
    }

    @ApiOperation(value = "修改")
    @PreAuthorize("@ss.hasPermi('system:post:edit')")
    @PutMapping
    public R edit(@RequestBody @Valid SysPostEditReq req) {
        boolean result = this.sysPostService.edit(req);
        return super.isSuccess(result);
    }


    @ApiOperation(value = "根据岗位ID查询")
    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('system:post:query')")
    public R<SysPostResp> findById(@PathVariable(value = "id") Long id) {
        SysPostResp resp = this.sysPostService.findById(id);
        return R.ok(resp);
    }


}